<template>
  <div class="customerManage">
    <view-header :title="'卫生评比'"></view-header>
    <div class="search_area">
      <el-row>
        <el-form :form="queryForm" label-width="1.2rem">
          <el-col :span="6">
            <el-form-item label="宿舍楼：">
              <el-input type="text" v-model="queryForm.buildingName" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="宿舍号：">
              <el-input type="text" v-model="queryForm.dormitoryNumber" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="检查日期：">
              <el-date-picker
                style="width: 100%;"
                v-model="queryForm.checkDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
                clearable>
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-form>
        <el-col :span="6">
          <div class="btn_area">
            <el-button class="confirm" @click="btnClick">查询</el-button>
            <el-button class="cancle" @click="reset">重置</el-button>
          </div>
        </el-col>
      </el-row>
    </div>
    <table-list :fields="fields" :list="list" :pagination="pagination" :total="total" @sizeChange="handleSizeChange" @currentChange="handleCurrentChange" @handle="onHandle"></table-list>
    <el-dialog title="卫生情况详情" :visible.sync="visible" width="60%" @close="close">
      <el-descriptions direction="vertical" :column="3" border>
        <el-descriptions-item label="所属宿舍楼" :contentStyle="{'text-align': 'center'}" :labelStyle="{'text-align': 'center'}">{{ evaluationForm.buildingName }}</el-descriptions-item>
        <el-descriptions-item label="宿舍管理员" :contentStyle="{'text-align': 'center'}" :labelStyle="{'text-align': 'center'}">{{ evaluationForm.buildingName }}</el-descriptions-item>
        <el-descriptions-item label="宿舍号" :contentStyle="{'text-align': 'center'}" :labelStyle="{'text-align': 'center'}">{{ evaluationForm.dormitoryNumber }}</el-descriptions-item>
        <el-descriptions-item label="检查日期" :span="1.5" :contentStyle="{'text-align': 'center'}" :labelStyle="{'text-align': 'center'}">{{ evaluationForm.checkDate }}</el-descriptions-item>
        <el-descriptions-item label="分数" :span="1.5" :contentStyle="{'text-align': 'center'}" :labelStyle="{'text-align': 'center'}">{{ evaluationForm.score }}</el-descriptions-item>
        <el-descriptions-item label="扣分项" :span="3" :contentStyle="{'text-align': 'center'}" :labelStyle="{'text-align': 'center'}">
          <div v-html="evaluationForm.deductionItem"></div>
        </el-descriptions-item>
      </el-descriptions>
      <span slot="footer" class="dialog-footer">
        <el-button class="cancle" @click="visible = false">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import tableList from '@/components/table.vue'
import viewHeader from '@/components/viewHeader.vue'
export default {
  name: 'customerManagement',
  components: {
    tableList,
    viewHeader
  },
  data() {
    return {
      queryForm: {
        "buildingName": "",
		    "checkDate": "",
		    "dormitoryNumber": ""
      },
      list: [],
      fields: [
        {
          prop: 'rowNum',
          label: '序号',
          align: 'center'
        },
        {
          prop: 'dormitoryNumber',
          label: '宿舍号',
          align: 'center'
        },
        {
          prop: 'buildingName',
          label: '宿舍楼名称',
          align: 'center'
        },
        {
          prop: 'checkDate',
          label: '检查日期',
          align: 'center'
        },
        {
          prop: 'score',
          label: '分数',
          align: 'center'
        },
        {
          prop: 'userName',
          label: '宿舍管理员',
          align: 'center'
        },
        {
          prop: 'oper',
          label: '操作',
          align: 'center',
          btns: [
            {type: 'primary',desc:'查看详情'},
          ]
        }
      ],
      pagination: {
        currentPage: 1,
        pageSize: 10
      },
      total: 0,
      user: {},
      evaluationForm: {
        deductionItem: ""
      },
      visible: false
    }
  },
  methods: {
    close() {
      this.evaluationForm = {
        deductionItem: ""
      };
    },
    onHandle(data) {
      let {row} = data;
      this.$http(this.$api.evaluation.info,this.reqData(row.uuid)).then(res => {
        if (res.data.code === 200) {
          this.evaluationForm = res.data.data;
          console.log(this.evaluationForm);
          this.visible = true
        } else {
          this.$message.error(res.data.message)
        }
      })
    },
    btnClick() {
      console.log(111);
      this.queryEvaluationList()
    },
    reset() {
      this.queryForm.buildingName = ""
      this.queryForm.checkDate = ""
      this.queryForm.dormitoryNumber = ""
      this.queryEvaluationList();
    },
    queryEvaluationList() {
      this.queryForm.adminId = this.user.permission == '01' ? "" : this.user.uuid;
      let url = this.$api.evaluation.list;
      this.$http(url,this.reqData(this.queryForm,this.pagination.currentPage,this.pagination.pageSize)).then(res => {
        if (res.data.code === 200) {
          let data = res.data.data;
          this.list = data.list;
          this.list.forEach((item,index) => {
            item.rowNum = (this.pagination.currentPage - 1) * this.pagination.pageSize + index + 1
          })
          this.total = this.list.length;
          console.log(data);
        } else {
          this.$message.error(res.data.message)
        }
      })
    },
    handleSizeChange(val) {
      console.log(val);
      this.pagination.pageSize = val;
      this.queryEvaluationList()
    },
    handleCurrentChange(val) {
      console.log(val);
      this.pagination.currentPage = val;
      this.queryEvaluationList()
    }
  },
  mounted() {
    this.user = JSON.parse(sessionStorage.getItem('user'));
    this.queryEvaluationList();
  }
}
</script>
<style lang="less" scoped>
.customerManage {
  background: #fff;
  overflow: hidden;
  padding-bottom: 0.15rem;
}
</style>